package com.buptse.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.buptse.model.ExcelPojo;
import com.buptse.service.InformationService;

import java.text.ParseException;


//excel解析监听器
public class ExcelUploadListener extends AnalysisEventListener<ExcelPojo> {

    private InformationService informationService;

    public ExcelUploadListener(InformationService informationService){
        this.informationService=informationService;
    }

    @Override
    public void invoke(ExcelPojo excelPojo, AnalysisContext analysisContext) {
        if(excelPojo.getCode()==null) return;
        //解析excel对象
        try {
            informationService.excelDecode(excelPojo.getCode(), excelPojo.getDescription());
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }


    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        //do nothing
    }
}
